package com.dream.myqiyi.ui;

import com.dream.myqiyi.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

public class HyperlinksViewActivity extends Activity{
	private EditText mHyperlinkUrlEdit;
	private EditText mHyperlinkNameEdit;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hyperlinks_view_activity);

		mHyperlinkUrlEdit = (EditText)findViewById(R.id.hyper_view_url_edit);
		mHyperlinkUrlEdit.requestFocus();
		mHyperlinkUrlEdit.setSelection(mHyperlinkUrlEdit.getText().toString().length());
		mHyperlinkNameEdit = (EditText)findViewById(R.id.hyper_view_name_edit);

		findViewById(R.id.hyper_view_ok_btn).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String hyperUrl = mHyperlinkUrlEdit.getText().toString();
				String hyperName = mHyperlinkNameEdit.getText().toString();
				if("".equals(hyperUrl)) {
		        	new AlertDialog.Builder(HyperlinksViewActivity.this)
					.setIcon(getResources().getDrawable(R.drawable.login_error_icon))
					.setTitle("创建链接错误")
					.setMessage("链接地址为空！")
					.create().show();
				} else {
					Intent intent = new Intent (HyperlinksViewActivity.this, NoteViewActivity.class);			
					Bundle newBundle = new Bundle();
					newBundle.putString("hyper_url", hyperUrl);
					newBundle.putString("hyper_name", hyperName);
					intent.putExtras(newBundle);
					HyperlinksViewActivity.this.setResult(NoteViewActivity.HYPERLINK_RESULT, intent);
					HyperlinksViewActivity.this.finish();
				}	
			}
			
		});
		findViewById(R.id.hyperlinks_view_reback_btn).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent (HyperlinksViewActivity.this, NoteViewActivity.class);			
				Bundle newBundle = new Bundle();
				newBundle.putString("hyper_url", "");
				intent.putExtras(newBundle);
				HyperlinksViewActivity.this.setResult(NoteViewActivity.HYPERLINK_RESULT, intent);
				HyperlinksViewActivity.this.finish();
			}
			
		});

	}
}
